package com.vf.admin.miaodong.dao;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppSuggest;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterSuggestDao.java
 * @Description 建议
 * @createTime 2021年07月23日 09:45:00
 */
@Repository
public class AfterSuggestDao extends BaseDao<AppSuggest> {

    /**
     * 新增或更新
     * @param appSuggest
     */
    public void saveOrUpdate(AppSuggest appSuggest) {
        if (appSuggest!=null && appSuggest.getId()!=null && appSuggest.getId()<=0) {
            this.update(appSuggest);
        } else {
            appSuggest.setId(this.add(appSuggest));
        }

    }

    /**
     * 综合查询
     * @param paramap
     * @param splitPageBean
     * @return
     */
    public List<AppSuggest> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        StringBuilder str = new StringBuilder("");
        str.append(" select * from app_suggest where 1=1 ");
        List<Object> list = new ArrayList<>();
        if (StringEx.isNotNull(paramap.get("userid"))) {
            str.append(" and userid = ? ");
            list.add(paramap.get("userid"));
        }

        if (StringEx.isNotNull(paramap.get("nick"))) {
            str.append(" and nick like ? ");
            list.add("%"+paramap.get("nick")+"%");
        }
        if (StringEx.isNotNull(paramap.get("phone"))) {
            str.append(" and phone = ? ");
            list.add(paramap.get("phone"));
        }

        if (StringEx.isNotNull(paramap.get("startDate"))) {
            str.append(" and createtime>=? ");
            list.add(paramap.get("startDate"));
        }
        if (StringEx.isNotNull(paramap.get("endDate"))) {
            str.append(" and createtime<=? ");
            list.add(paramap.get("endDate"));
        }
        str.append(" order by createtime desc ");

        String sql = str.toString();
        return this.queryList(sql, list, AppSuggest.class, splitPageBean);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id) {
        StringBuilder str = new StringBuilder("");
        str.append(" delete from app_suggest where id = ? ");
        ArrayList<Object> list = new ArrayList<>();
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }


}